﻿using System.Collections.Generic;
using System.Xml.Serialization;
using System;

namespace SampleHelper
{
    public class ItemInfo
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public string Screenshot { get; set; }

        Dictionary<string, List<string>> _properties = new Dictionary<string, List<string>>();

        public Dictionary<string, List<string>> GetGroupedProperties()
        {
            return _properties;
        }

        public Property[] Properties
        {
            get
            {
                List<Property> values = new List<Property>();
                foreach (var key in _properties.Keys)
                {
                    foreach (var v in _properties[key])
                    {
                        Property kvp = new Property();
                        kvp.Key = key;
                        kvp.Value = v;
                        values.Add(kvp);
                    }
                }
                return values.ToArray();
            }
            set
            {
                _properties = new Dictionary<string, List<string>>();
                foreach (var v in value)
                {
                    AddProperty(v.Key, v.Value);
                }
            }

        }

        public void AddProperty(string key, string v)
        {
            List<string> values;
            if (_properties.ContainsKey(key))
            {
                values = _properties[key];
            }
            else
            {
                values = new List<string>();
                _properties.Add(key, values);
            }

            if (!values.Contains(v))
            {
                values.Add(v);
            }
        }

        public List<string> GetProperties(string key)
        {
            if (_properties.ContainsKey(key))
            {
                return _properties[key];
            }
            return null;
        }

        public List<string> GetKeys()
        {
            List<string> keys = new List<string>();
            foreach (var k in _properties.Keys)
            {
                keys.Add(k);
            }
            return keys;
        }
       
        public string Url = string.Empty;
    }

    public class Property
    {
        [XmlAttribute]
        public string Key { get; set; }

        [XmlAttribute]
        public string Value { get; set; }
    }
}
